package ld.oauth.blog.controller.file;

import com.ld.common.ResultInfoFactory;
import ld.oauth.blog.service.file.FileService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/fastdfs")
@Slf4j
public class FileController {

    @Autowired
    private FileService fileService;

    /**
     * 文件上传
     * @param file
     * @return
     */
    @PostMapping("/uploadFile")
    public ResultInfoFactory<String> uploadFile(@RequestBody MultipartFile file) {
        return ResultInfoFactory.success(fileService.uploadFile(file));
    }

    /**
     * 删除图片
     * @param fileUrl
     * @return
     */
    @GetMapping("/deleteImg")
    public ResultInfoFactory deleteImg(String fileUrl) throws Exception {
        fileService.deleteImg(fileUrl);
        return ResultInfoFactory.success();
    }


}
